// var gulp = require("gulp");
const { src, dest, watch, parallel, series } = require('gulp');
const postcss = require('gulp-postcss');
const sass = require('gulp-sass')(require('sass'));
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');

var autoprefixer = require('autoprefixer');
var postcssNested = require('postcss-nested');
var tailwindcss = require('tailwindcss');
var tailwindConfig = require('./tailwind.config');

var processors = [tailwindcss(tailwindConfig), postcssNested, autoprefixer];

function css() {
  return src('./src/theme/test/assets/lib/*.scss').pipe(postcss(processors)).pipe(sass().on('error', sass.logError)).pipe(dest('./src/theme/test/assets'));
}

// JS 压缩任务
function minifyEventJs() {
  return src('./src/theme/default/assets/collect.js')
    .pipe(uglify({}))
    .pipe(rename({ suffix: '.min', name: 'event' }))
    .pipe(dest('./src/theme/default/assets/'));
}

function buildEventJs() {
  return src('./src/theme/default/assets/collect.js')
    .pipe(uglify({}))
    .pipe(rename({ basename: 'event' }))
    .pipe(dest('./src/theme/default/assets/'));
}

exports.dev = function (cb) {
  css();
  cb();
};

exports.minifyEventJs = minifyEventJs;
exports.buildEventJs = buildEventJs;
